package com.ppm.common.control;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ppm.common.dao.CommonHibernateDAO;
import com.ppm.common.model.User;




@Service
public class UserService {
	
	@Autowired
	private CommonHibernateDAO<User> userDAO;
	
	
	public User login(String username,String password)
	{
		try {
			User user=new User();
			user.setUsername(username);
			user.setPasswd(password);
			List<User> users=userDAO.findByExample(user);
			if(users==null || users.size()==0)
			{
				return null;
			}else
			{
				return users.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	public List<User> find()
	{
		
		try {
			return userDAO.findAll(User.class);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			
			e.printStackTrace();
			return null;
		}
	
	}


	public CommonHibernateDAO<User> getUserDAO() {
		return userDAO;
	}


	public void setUserDAO(CommonHibernateDAO<User> userDAO) {
		this.userDAO = userDAO;
	}
	
	
	
	
}
